<!-- 考勤-基础设置-考勤机打卡 -->
<template>
  <div class="wrap">
    <div class="header">
      <div>
        <a-input-search
          :style="{ width: '220px' }"
          placeholder="考勤机名称"
          search-button
          @search="onSearch"
          @press-enter="onSearch"
          v-model="nameSearch"
        />
      </div>
      <div>
        <a-button type="primary" @click="add(null)" style="margin-right: 10px"
          >新增考勤机</a-button
        >
        <a-button type="outline" @click="edit(null)">导入打卡地址</a-button>
      </div>
    </div>
    <table-turn :table-data="getTableData" ref="tableRef">
      <a-table-column :width="80">
        <template #title> 序号 </template>
        <template #cell="{ rowIndex }">
          {{ rowIndex + 1 }}
        </template>
      </a-table-column>
      <a-table-column :width="200" data-index="name" title="设备名称">
      </a-table-column>
      <a-table-column :width="200" data-index="definition" title="SN码">
      </a-table-column>
      <a-table-column :width="200" data-index="definition" title="考勤机类型">
      </a-table-column>
      <a-table-column :width="200" data-index="definition" title="网络状态">
      </a-table-column>
      <a-table-column :width="200" data-index="definition" title="考勤组人数">
      </a-table-column>
      <a-table-column :width="200" data-index="definition" title="管理员">
      </a-table-column>
      <a-table-column :width="200" data-index="definition" title="最后修改时间">
      </a-table-column>
      <a-table-column :width="200" data-index="" title="操作" fixed="right">
        <template #cell="{ record }">
          <a-tooltip content="编辑">
            <IconFont
              type="icon-edit"
              :size="26"
              :style="{
                marginRight: '10px',
                cursor: 'pointer'
              }"
              @click="goEdit(record)"
            />
          </a-tooltip>
          <a-tooltip content="删除" position="left">
            <a-popconfirm content="是否确认删除该条数据?" @ok="del(record.id)">
              <icon-font
                type="icon-delete"
                :size="26"
                :style="{
                  cursor: 'pointer',
                  marginRight: '10px'
                }"
              />
            </a-popconfirm>
          </a-tooltip>
        </template>
      </a-table-column>
    </table-turn>
  </div>
</template>

<script lang="ts" setup>
let modalVisible = ref(false); // 判断新增弹出框是否打开
let currData = ref(); // 储存当前选中数据
let tableRef = ref();
let nameSearch = ref(''); // 搜索框值

// 新增
const add = (record: any) => {
  modalVisible.value = true;
};

// 获取表格数据
const getTableData = async () => {
  try {
    // originData.value = await GetHumanChangeSetting({
    //   typeId: 1 // 人事异动默认传1
    // });
    // const res: any = originData.value.find(
    //   (item: any) => item.id === currId.value
    // );
    // res.content = res.personnelChange;
    // return Promise.resolve(res.personnelChange);
  } catch (error: unknown) {
    console.log(error);
  }
};

const onSearch = () => {
  refresh();
};

// 编辑
const goEdit = (record: any) => {
  console.log(record);
  currData.value = record;
  modalVisible.value = true;
};

// 删除某一行
const del = async (id: number) => {
  try {
    // await DelHumanChangeSetting({ id });
    refresh();
  } catch (error: unknown) {
    console.log(error);
  }
};

// 弹窗自定义事件
const indexEmit = async (record: any) => {
  //
};
// 刷新表格数据
const refresh = () => {
  tableRef.value.loadData();
};
</script>

<style lang="less" scoped>
.wrap {
  padding: 10px 20px;
  .header {
    display: flex;
    justify-content: space-between;
    margin: 20px 0;
  }
}
</style>
